<?php
require_once ('ini_set.inc');
require_once ('LyException.php');
require_once ('db.php');
require_once ('ClassUtil.php');
require_once ('GenerateObj.php');
class Content extends GenerateObj{
	
	protected $fields=array("id","title","content","user_id","weight","type_id","create_time");
	protected $table_name="content";
	//that fields only ready by public don't write ,write using function
	public $id;
	public $title;
	public $content;
	public $user_id;
	public $weight;
	public $type_id;
	public $create_time;
	//public $user_category ;

	public function __construct(){
		$args=func_get_args();
		print_r ($args);
		ClassUtil::callMethodForArgs($this,$args);
	}
	public function construct_(){
	}
	public  function construct_number($id){
		$this->id=$id;
		$this->generate_obj_by_field("id",$id);
	}
	
	public function construct_string_string_number_number_number($title,$content,$user_id,$weight,$type_id){
		$this->title=$title;
		$this->content=$content;
		$this->user_id=$user_id;
		$this->weight=$weight;
		$this->type_id=$type_id;
	}
	
	private function db_save_content($title,$content,$user_id,$weight,$type_id){
		$sql="insert into content (title,content,user_id,weight,type_id) values ('$title','$content',$user_id,$weight,$type_id)";
		$query = db_query($sql, "users", "write");
		if(!mysql_insert_id()) throw new LyException("save content fails");
		return mysql_insert_id();
	}
	public function save(){
		$id=$this->db_save_content($this->title,$this->content,$this->user_id,$this->weight,$this->type_id);
		//generate_obj_by_field("id",$id);
		$this->id=$id;
		$this->create_time=date("Y-m-d H:i:s");
	}
}
?>